package com.lindroy.jetpacknotes.logic.network

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.lindroy.jetpacknotes.logic.model.ArticleResp
import com.lindroy.jetpacknotes.paging.RepoPagingSource
import kotlinx.coroutines.flow.Flow

/**
 * @author Lin
 * @date 2022/1/14
 * @function
 */
object Repository {

    private const val PAGE_SIZE = 25

    private val apiService = ApiService.create()

    val pagingData: Flow<PagingData<ArticleResp>>
        get() = Pager(
            //initialLoadSize 参数不传的话，第一次加载时会默认加载 PAGE_SIZE 三倍的数据
            config = PagingConfig(PAGE_SIZE, initialLoadSize = PAGE_SIZE),
            pagingSourceFactory = { RepoPagingSource(apiService) }).flow
}